// For more information about this file see https://dove.feathersjs.com/guides/cli/log-error.html
import type { HookContext, NextFunction } from '../declarations';
import { logger } from '../logger';

export const logError = async (context: HookContext, next: NextFunction) => {
	try {
		await next();
	// eslint-disable-next-line @typescript-eslint/no-explicit-any
	} catch (error: any) {
		logger.error(error.stack);

		// Log validation errors
		if (error.data) {
			logger.error('Data: %O', error.data);
		}

		throw error;
	}
};
